Conditions | 3 |
Total Lines | 64 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | const httpProcessor = require('../HttpProcessor'); |
||
40 | async handle(IdFilter) |
||
41 | { |
||
42 | if (!IdFilter.isSuccessful()) { |
||
43 | const generatedKey = this.generateSecretKey(this.partnerId, this.apiKey); |
||
44 | const jobId = md5(Date.now() + randomNumber(1000000000)); |
||
45 | |||
46 | const idType = IdFilter.getIDType(); |
||
47 | const country = IdFilter.getCountry(); |
||
48 | const url = '/v1/id_verification'; |
||
49 | |||
50 | const idNumber = IdFilter.getIDNumber(); |
||
51 | const firstName = IdFilter.getFirstName(); |
||
52 | const lastName = IdFilter.getLastName(); |
||
53 | const middleName = IdFilter.getMiddleName(); |
||
54 | const dateOfBirth = IdFilter.getDOB(); |
||
55 | const phone = IdFilter.getPhoneNumber(); |
||
56 | const userId = IdFilter.getUserId(); |
||
57 | const company = IdFilter.getCompany(); |
||
58 | |||
59 | const body = { |
||
60 | 'partner_id' : this.partnerId, |
||
61 | 'timestamp' : generatedKey.timestamp, |
||
62 | 'sec_key' : generatedKey.secretKey, |
||
63 | 'country' : country.toUpperCase(), |
||
64 | 'id_type' : idType, |
||
65 | 'id_number' : idNumber, |
||
66 | 'middle_name' : middleName, |
||
67 | 'first_name' : firstName, |
||
68 | 'last_name' : lastName, |
||
69 | 'phone_number' : phone, |
||
70 | 'dob' : dateOfBirth, |
||
71 | 'company' : company, |
||
72 | 'partner_params' : { |
||
73 | 'job_id' : jobId, |
||
74 | 'job_type' : 5, |
||
75 | 'user_id' : userId |
||
76 | } |
||
77 | |||
78 | }; |
||
79 | |||
80 | try { |
||
81 | const response = await this.process('POST', url, body); |
||
82 | |||
83 | IdFilter.confirmSuccess(); |
||
84 | |||
85 | IdFilter.setHandler(this.client); |
||
86 | |||
87 | IdFilter.setData({ |
||
88 | 'handler' : IdFilter.getHandler(), |
||
89 | 'country' : IdFilter.getCountry().toUpperCase(), |
||
90 | 'message' : idType + ' Verified' + ' Successfully', |
||
91 | 'data' : response |
||
92 | }); |
||
93 | |||
94 | return IdFilter.getData(); |
||
95 | |||
96 | } catch (error) { |
||
97 | IdFilter.setError({'error' : error}); |
||
98 | |||
99 | return IdFilter.getError(); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | } |
||
104 | |||
154 | module.exports = Smile; |